const fsPromise = require("fs/promises");
const path = require("path");

/**
 * 创建深层目录
 * @param {*} dir
 */
exports.mkdir = function (dir) {
  return new Promise(async (resolve, reject) => {
    const isAccess = await fsPromise
      .access(dir)
      .then(() => true)
      .catch(() => false);
    if (!isAccess) {
      await exports.mkdir(path.dirname(dir));
      await fsPromise.mkdir(dir).catch(reject);
    }

    resolve();
  });
};
